window.gData = {} // 全局数据
window.isLoadDataOver = false // 所有的html数据加载完毕的标识
// const gExistData = {}

// 加载静态数据
recurArr({ dateList: window.dateList, index: 0 }, function () {
  // debugger
  window.isLoadDataOver = true
})

// 递归动态加载所有数据
function recurArr ({ dateList, index }, fn) {
  const arr = dateList
  // debugger
  if (index < arr.length) {
    const value = arr[index].value
    // const src = './data/' + value + '.js'
    const src = window.prefixUrl + '/data/' + value + '.js'
    // debugger
    loadScript(src, value, function () {
      // debugger
      if (!window.gData[value]) {
        window.gData[value] = {}
      }
      window.gData[value] = {
        rigthAnswer: window.rigthAnswer,
        rightAnswerA: window.rightAnswerA,
        testQuestion: window.testQuestion,
        allData: window.allData
      }
      index++
      this.recurArr({ dateList, index }, fn)
    })
  } else {
    // debugger
    fn && fn()
  }
}

// debugger
// 通过复制word文档得试题，正则匹配，得出正确答案+题目对应的章节
var initCurData = window.initCurData = function (testQuestion) {
  const regSecialSymbols = /(\n|\r|\r\n|↵)/g // 正则：换行符等
  // debugger
  var testList = testQuestion.split('==-=--=')
  // 剔除数组的空元素
  testList = testList.filter(function (s) {
    return s && s.trim()
  })

  // debugger
  window.rightAnswerA = '' // 正确答案+对应章节
  window.rigthAnswer = '' // 正确答案

  // debugger
  testList.forEach(function (o, i) {
    try {
      const arr1 = o.split('|*|*|')
      const answer1 = arr1[1].split('||-||') // 获取答案+题目对应的章节
      var charter = answer1[1] // 题目对应的章节

      if (charter.match(regSecialSymbols)) {
        const charter1 = charter.split(regSecialSymbols)
        charter = charter1[0]
        // debugger
      }

      const rightAnswer1 = answer1[0].split(regSecialSymbols) // ["正确答案：B", "↵", "    解析：PMBOK(6)P244- "]
      const rightAnswer2 = rightAnswer1[0].split(/[:|：]/g) // ["正确答案", "B"]
      let right = rightAnswer2[1] // 正确答案 B

      const sysBolReg = /,|，/g
      const hasSysbol = right.match(sysBolReg)
      var right1 = right
      if (hasSysbol) {
        // debugger
        right = right.replace(sysBolReg, '')
        // debugger
        right1 = '(' + right.trim() + ')'
        // debugger
      }
      window.rightAnswerA += right.trim() + ' ' + charter + ',' // 正确答案+对应章节
      window.rigthAnswer += right1 // 正确答案
      // debugger
    } catch (error) {
      debugger
    }
  })
  // console.log('window.rightAnswerA', window.rightAnswerA)
  // console.log('window.rigthAnswer', window.rigthAnswer)
}

